import { defineStore, storeToRefs } from 'pinia';
import { computed, ref } from 'vue';

import { useCounter2Store } from './counter2';
console.log('[ 2 ] >', 2);
// 在这里调用时，早了，因为 pinia 还没装上，不能放这里，会报如下错误：
// Uncaught Error: [🍍]: getActivePinia was called with no active Pinia. Did you forget to install pinia?
// let { count: count2 } = storeToRefs(useCounter2Store());

// 这个函数我们一般起名格式形如：useXxxStore
export const useCounterStore = defineStore('counter', () => {
  console.log('[ 1 ] >', 1);
  let { count: count2 } = storeToRefs(useCounter2Store());

  const count = ref(0);

  const doubleCount = computed(() => count.value * 2);

  const addCount = () => {
    // count.value++;
    // counter2Store.count++; // 这还是否支持响应式，支持的
    count2.value++;
  };

  return { count, addCount, doubleCount };
});
